package Grid;

import Data.Data;

/*
 * This enable to print the grid un a 2 dimension structure
 * 
 */
public class Map {
    Grid g;

    public Map(Grid g) {
        this.g = g;
    }

    // update the grid
    public void setGrid(Grid g) {
        this.g = g;
    }

    // print the map
    public String toString() {
        String s = "";
        String wordLine = "";
        String gap = "";
        String line = "|";
        String stat = "|";

        for (int i = 0; i < Data.caseLength; i++) {
            wordLine += "_";
            gap += " ";
        }

        for (int i = 0; i < g.getLength(); i++) {
            line += wordLine + "|";
        }

        line += "\n";

        s += " ";
        for (int i = 0; i < g.getLength(); i++) {
            s += wordLine + " ";
        }
        s += "\n";

        for (int i = 0; i < g.getHeight(); i++) {
            s += "|";
            stat = "|";
            for (int j = 0; j < g.getLength(); j++) {
                if (g.getElement(i, j).getName() == Data.nullElementName) {
                    s += gap + "|";
                    stat += gap + "|";

                } else if (g.getElement(i, j).getName() == Data.humanName) {
                    s += Data.humanName + "|";
                    if (g.getElement(i, j).getIsAlive()) {
                        stat += g.getElement(i, j).getStat() + "|";
                    } else {
                        stat += Data.deadName + "|";
                    }
                } else {
                    s += g.getElement(i, j).getName() + "|";
                    stat += g.getElement(i, j).getStat() + "|";
                }
            }

            s += "\n" + stat + "\n" + line;

        }

        return s;

    }
}
